//  this library.
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/view_util.dart';

/// 考试情况
class ResultExamWidget extends StatelessWidget {
  /// 总题数
  final int total;

  /// 正确题数
  final int success;

  /// 错误题数
  final int error;

  /// 总用时，单位：分钟
  final int time;

  const ResultExamWidget({
    super.key,
    required this.total,
    required this.success,
    required this.error,
    required this.time,
  });

  @override
  Widget build(BuildContext context) {
    debugPrint("resultExamWidget 组件 -> build方法执行 ===> ");
    debugPrint("");
    return Container(
      height: 276,
      padding: EdgeInsets.all(30),
      decoration: BoxDecoration(
        color: colorWhite1,
        borderRadius: BorderRadius.all(Radius.circular(20)),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          _titleItem(),
          _bottomItems(),
        ],
      ),
    );
  }

  /// 标题显示
  _titleItem() {
    return Row(
      children: [
        SvgPicture.asset(
          "images/question/result_exam_title.svg",
          width: 30,
          height: 30,
        ),
        hiSpace(width: 10),
        Text(
          "考试情况",
          style: FontUtil.fontBlack9(30, fontWeight: FontWeight.w500),
        )
      ],
    );
  }

  /// 底部显示
  _bottomItems() {
    return Container(
      height: 136,
      padding: EdgeInsets.symmetric(vertical: 15),
      decoration: BoxDecoration(
        color: colorGrey12,
        borderRadius: BorderRadius.all(Radius.circular(12)),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          _bottomItem(
            title: "一共",
            value: total.toString(),
            valueSuf: "题",
            textColor: colorBlue1,
          ),
          _bottomItem(
            title: "答对",
            value: success.toString(),
            valueSuf: "题",
            textColor: colorGreen10,
          ),
          _bottomItem(
            title: "答错",
            value: error.toString(),
            valueSuf: "题",
            textColor: colorRed5,
          ),
          _bottomItem(
            title: "总用时",
            value: time.toString(),
            valueSuf: "分钟",
            textColor: colorBlue1,
          ),
        ],
      ),
    );
  }

  /// 底部组件显示
  _bottomItem({
    bool end = false,
    required String title,
    required String value,
    required String valueSuf,
    required Color textColor,
  }) {
    return Container(
      // width: 157,
      // decoration: BoxDecoration(
      //   border: end
      //       ? null
      //       : Border(
      //     right: BorderSide(
      //       color: colorGrey13,
      //       width: 1,
      //     ),
      //   ),
      // ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Text(
            title,
            style: FontUtil.fontGrey1(20),
          ),
          Text.rich(
            TextSpan(
              children: [
                TextSpan(
                  text: value,
                  style: _itemTextStyle(textColor, 28),
                ),
                TextSpan(
                  text: valueSuf,
                  style: _itemTextStyle(textColor, 20),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  /// 底部字体样式
  _itemTextStyle(Color textColor, double fontSize) {
    return TextStyle(
      fontSize: fontSize,
      fontWeight: FontWeight.w400,
      color: textColor,
    );
  }
}
